package com.lun.swordtowardoffer2.c11;

public class PeakIndexInMountainArray {

	public int peakIndexInMountainArray(int[] nums) {
		int left = 1, right = nums.length - 2;
		
		while(left <= right) {
			int mid = left + (right - left) / 2;
			
			if(nums[mid -1] < nums[mid] && nums[mid] > nums[mid + 1]) {
				return mid;
			}
			
			if(nums[mid - 1] < nums[mid]) {
				left = mid + 1;
			}else {
				right = mid - 1;
			}
			
		}
		
		return -1;
	}
	
}
